﻿'use strict';

// Demonstrate how to register services
// In this case it is a simple value service.
angular.module('app.services', [])

    .value('version', '0.1');

app.service('drinksService', function () {

    // Get all existing drinks
    this.getDrinks = function () {
        return drinks;
    };

    // Get a specific drink
    this.getDrink = function (id) {
        for (var i = 0; i < drinks.length; i++) {
            if (drinks[i].id === id)
                return drinks[i];
        }
        return null;
    }

    // Create a new drink
    this.insertDrink = function (name, ingredients, garnish, description) {
        var id = drinks.length + 1;
        drinks.push({
            id: id,
            name: name,
            ingredients: ingredients,
            garnish: garnish,
            description: description
        });
    };

    // Remove a drink
    this.deleteDrink = function (id) {
        for (var i = drinks.length - 1; i >= 0; i--) {
            if (drinks[i].id === id) {
                drinks.splice(i, 1);
                break;
            }
        }
    };

    var drinks = [{
        id: 1,
        name: 'Mojito',
        ingredients: [
            '1.5 oz. Rum (Light)',
            '12 Mint Leaves',
            '.5 oz. Lime Juice',
            '.5 oz. Simple Syrup',
            'Club Soda / Carbonated Water'
        ],
        garnish: 'Mint Leaves or Lime Wheel',
        description: 'In a Collins glass, place mint leaves, simple syrup and lime juice. Muddle them well. Fill glass with ice. Add rum and fill it with club soda.'
    },
    {
        id: 2,
        name: 'Snake Bite',
        ingredients: [
            '2 oz. Yukon Jack® Whiskey',
            'Splash of Lime Juice'
        ],
        garnish: null,
        description: 'Pour ingredients into a shaker with ice. Shake and strain into a shot glass.'
    },
    {
        id: 3,
        name: 'Sour Watermelon Martini',
        ingredients: [
            '2 oz. Watermelon Pucker',
            '1 oz. Vodka',
            '1 oz. Triple Sec'
        ],
        garnish: 'Cherry',
        description: 'Pour all ingredients into a shaker with ice. Shake and strain into a chilled martini glass.'
    }];
});